﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Configuration;
using WebTemplate.DAL.Entities;

namespace WebTemplate.DAL.Repositories
{
    class CourseMaterialsRepository
    {
        //public void Insert(CourseMaterials Item)
        //{
        //    SqlConnection connection = new SqlConnection();
        //    connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

        //    SqlCommand command = new SqlCommand();
        //    command.Connection = connection;
        //    command.CommandText = "[CourseMaterials_Insert]";
        //    command.CommandType = System.Data.CommandType.StoredProcedure;
        //    command.Parameters.AddWithValue("@DoctorInCoursesID", Item.DoctorInCoursesID);
        //    command.Parameters.AddWithValue("@File", Item.File);
        //    connection.Open();
        //    command.ExecuteNonQuery();
        //    connection.Close();
        //}

        //public void Update(CourseMaterials Item)
        //{
        //    SqlConnection connection = new SqlConnection();
        //    connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        //    SqlCommand command = new SqlCommand();
        //    command.Connection = connection;
        //    command.CommandText = "[CourseMaterials_Insert]";
        //    command.CommandType = System.Data.CommandType.StoredProcedure;
        //    command.Parameters.AddWithValue("@ID" ,Item.ID );
        //    command.Parameters.AddWithValue("@DoctorInCoursesID", Item.DoctorInCoursesID);
        //    command.Parameters.AddWithValue("@File", Item.File);
        //    connection.Open();
        //    command.ExecuteNonQuery();
        //    connection.Close();
        //}

        public void Delete(int ID)
        {
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            SqlCommand command = new SqlCommand();
            command.Connection = connection;
            command.CommandText = "[CourseMaterials_Insert]";
            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@ID", ID);
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }

            public List<CourseMaterial> Select(CourseMaterialSearchCriteria Item)
       {
           SqlConnection connection = new SqlConnection();
           connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
           SqlCommand command = new SqlCommand();
           command.Connection = connection;
           command.CommandText = "[CourseMaterial_Select]";
           command.CommandType = System.Data.CommandType.StoredProcedure;
        
           command.Parameters.AddWithValue("@CourseSemesterId", Item.CourseSemesterId);
           
           connection.Open();

           SqlDataReader reader = command.ExecuteReader();
           List<CourseMaterial> reg = new List<CourseMaterial>();

           while (reader.Read())
           {
               CourseMaterial obj = new CourseMaterial();

               obj.FileName = reader.GetString(0);
               obj.FileUrl = reader.GetString(1);
               obj.CourseSemesterId = reader.GetInt32(2);

               reg.Add(obj);

           }
           connection.Close();

           return reg;
       }
    }
    }
}
